/**
 * 横式菜单栏应用资源菜单处理
 */
var divcontent='';
$(function() {
	var data = orange.getResourceData();
	var content='',panel = $("#indexMenu").panel();
	for(var i=0; i<data.length; i++) {
		var title = data[i].name;
		var href=data[i].url;
		var iconCls = data[i].icon;
		var children = data[i].children;
		if(children.length==0){
			content += '<a href="#" class="easyui-linkbutton" data-options="iconCls:\''+iconCls+' color-icon\'" onclick=_indexMainTabs.addModule(\''+title+'\',\''+href+'\')>'+title+'</a>';
		}else{
			var menu = "#menu_"+ data[i].id;
			content += '<a href="#" class="easyui-menubutton" data-options="menu:\''+menu+'\',iconCls:\''+iconCls+' color-icon\'">'+title+'</a>';
			var childcontent=renderChildrenData (children);
			content += '<div id="menu_'+data[i].id+'">'+childcontent+'</div>';
		}
		divcontent='';
	}
	$("#indexMenu").panel('clear');
	$("#indexMenu").panel('body').append('<div>'+content+'</div>');
	$.parser.parse(panel);
});

function renderChildrenData (childlist) {
	for(var i=0;i<childlist.length;i++) {
		var menucontent='';
		var url=childlist[i].url;
		var name = childlist[i].name;
		var icon = childlist[i].icon;
		var child = childlist[i].children;
		if(child.length==0){
			menucontent += '<div  data-options="iconCls:\''+icon+' color-icon\'" onclick=_indexMainTabs.addModule(\''+name+'\',\''+url+'\')>'+name+'</div>';
			divcontent += menucontent;
		}else{
			divcontent += '<div><span>'+name+'</span><div>';
			renderChildrenData(child);
			divcontent += '</div></div>';
		}
	}
	return divcontent;
}
